package com.example.demo.controller;


import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/")
    public User insertUser()throws Exception{
        User user=new User();
        user.setUsername("lixingzhen");
        userService.insertUser(user);
        return user;
    }

    @GetMapping("/{id}")
    public User findUserById(@PathVariable long id)throws Exception{
        User user =userService.findUserById(id);
        System.out.println(user.getId()+"这是有个空格"+user.getUsername());
        return user;

    }

    @PutMapping("/{id}")
    public User updateUserById(User user){
        return userService.updateUserById(user);
    }
    @DeleteMapping("/{id}")
    public void deleteUserById(@PathVariable long id){
        userService.deleteUserById(id);
    }
}
